package com.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.service.CommentsService;

import javax.annotation.Resource;

@CrossOrigin
@RestController
public class CommentsController {

    @Autowired
    CommentsService commentsService;

    @GetMapping("/getComments")
    public Object getComments(@RequestParam Integer id){
        return JSON.toJSONStringWithDateFormat(commentsService.getComments(id),"yyyy-MM-dd HH:mm:ss");
    }

    @GetMapping("/addComment")
    public Object addComment(@RequestParam Integer id,@RequestParam String content){
        return JSON.toJSONString(commentsService.addComment(id, content));
    }
}
